<?php
    @session_start();
    include "connect.php";
	$masv=$_SESSION['sv'];
	$ghichu=$_POST["yk"];
	$stt=$_POST["stt"];
	$ma_hp=$_POST["ma"];
	$hknk=$_POST["hk"];
	$t3=mysql_query("update hoc set ghi_chu='$ghichu' where ma_sv='$masv'  and stt_nhom='$stt' and ma_hp='$ma_hp' and ma_hknk='$hknk'");
	$sql=mysql_query("select * from `danh gia` where ma_sv='$masv' and stt_nhom='$stt' and ma_hp='$ma_hp' and ma_hknk='$hknk'");
	$count=mysql_num_rows($sql);
	if($count>0)//da tung luu trong csdl
	{
	     $sql1=mysql_query("select a.ma_tc,a.noidung_tc from `tieu chi` a, `tieuchi hocki` b where a.ma_tc=b.ma_tc and b.ma_hknk=(select max(ma_hknk) from `hocki nienkhoa`) ");
		  
		 while($row=mysql_fetch_row($sql1))
		{
			  $matc=$row[0];
			  $noidung=$row[1];
			  $muc=$_POST["$matc"];
			  $str=mysql_query("update `danh gia` set `muc danh gia`='$muc' where ma_sv='$masv' and ma_hp='$ma_hp' and stt_nhom='$stt' and ma_hknk='$hknk' and ma_tc='$matc'");
			  
		}//ngoac while
	}//ngoac if
	else //chua co trong csdl
	{
	    $sql1=mysql_query("select a.ma_tc,a.noidung_tc from `tieu chi` a, `tieuchi hocki` b where a.ma_tc=b.ma_tc and b.ma_hknk=(select max(ma_hknk) from `hocki nienkhoa`) ");
	    while($row=mysql_fetch_row($sql1))
		{
			  $matc=$row[0];
			  $noidung=$row[1];
			  $muc=$_POST["$matc"];
			  $str=mysql_query("insert into `danh gia` values('$masv','$ma_hp','$hknk','$stt','$matc','$muc') ");
			  
		}//ngoac while
	}//ngoac else
	echo "<meta http-equiv='refresh' content='0; URL=sv-chonhp.php ' />";
	
?>
